package cn.tedu.yl.Patients.service;

import cn.tedu.yl.Patients.mapper.PatientMapper;
import cn.tedu.yl.Patients.pojo.entity.Patient;
import cn.tedu.yl.base.response.PageData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.time.LocalDateTime;
import java.util.List;


@Service
public class PatientService {

    @Autowired
    private PatientMapper patientMapper;

    public PageData getAll() {
        List<Patient> patients = patientMapper.selectList(null);
        PageData list = new PageData();
        list.setList(patients);
        list.setTotal(patients.size());
        return list;
    }

    public void create(Patient patient) {
        patient.setCreateTime(LocalDateTime.now());
        patientMapper.insert(patient);
    }

    public void update( Patient patient) {
        patient.setUpdateTime(LocalDateTime.now());
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",patient.getId());
        patientMapper.update(patient,queryWrapper);
    }

    public void delete(Long id) {
        patientMapper.deleteById(id);
    }
}
